<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>物资入库记录列表</title>
    <jsp:include page="/WEB-INF/view/commons/css.jsp" />
</head>
<body >
<div id="main-container" class="container-fluid">
    <form action="appMaterialsIn/dolist" method="post" name="searchForm" id="searchForm" role="form" class="form-horizontal">
        <input type="hidden" name="orgId" id="orgId" value="">
        <div class="form-group">
                <label class="col-sm-1 control-label">单号：</label>
                <div class="col-md-4">
                            <input type="text" class="form-control" name="inCode" value="${entity.inCode}" placeholder="单号">
                </div>
                <label class="col-sm-1 control-label">主题：</label>
                <div class="col-md-4">
                            <input type="text" class="form-control" name="inTitle" value="${entity.inTitle}" placeholder="主题">
                </div>
        </div>
        <div class="form-group">
            <label class="col-sm-1 control-label">来往单位：</label>
            <div class="col-md-2">
                <d:select clazz="selectpicker" list="${orgTypes}" name="orgType" id="selorgtype" selected="${orgType}"></d:select>
            </div>
            <div class="col-md-2" style="padding-right: 0;display: ${orgType eq '1'?'block':'none'}" id="inOrg">
                <d:select clazz="selectpicker" list="${orgLists}" name="orgIds" id="selinorg" selected="${searchEntity.orgId}"></d:select>
            </div>
            <div class="col-md-2" style="padding-right: 0;display: ${orgType eq '2'?'block':'none'}" id="outOrg">
                <d:select clazz="selectpicker" list="${outLists}" name="orgIds" id="seloutorg" selected="${searchEntity.orgId}"></d:select>
            </div>
            <label class="col-sm-1 control-label">入库状态：</label>
            <div class="col-md-4">
                <d:select clazz="selectpicker" list="${inStatus}" name="inStatus" id="inStatus" selected="${searchEntity.inStatus}"></d:select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-1 control-label">发起时间：</label>
            <div class="col-md-6">
                <div class="input-group">
                    <input type="text"  class="span1 Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd', maxDate:'#F{$dp.$D(\'endTimeStr\')}'})" id="beginTimeStr" name="beginTimeStr" value="${searchEntity.beginTimeStr}" placeholder="开始时间" />
                    至 <input type="text"  class="span1 Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd', minDate:'#F{$dp.$D(\'beginTimeStr\')}'})" id="endTimeStr" name="endTimeStr" value="${searchEntity.endTimeStr}" placeholder="结束时间" />
                    <button id="searchBtn" type="button" class="btn btn-sm btn-info" style="margin-left:10px;margin-right: 10px;"><i class="fa fa-search"></i> 搜索</button>
                    <shiro:hasPermission name='APP_MATERIALS_IN:add'>
                        <button type="button" data-url="appMaterialsIn/create" class="btn btn-sm btn-success link_add" data-title="新增物资入库记录"><i class="fa fa-plus"></i> 起草 </button>
                    </shiro:hasPermission>
                </div>
            </div>
        </div>
    </form>
    <table id="table_data" class="table table-striped table-bordered table-hover">
        <thead>
        <tr>
            <th width="10%">单号</th>
            <th width="10%">主题</th>
            <th width="10%">来往单位名称</th>
            <th width="10%">经办人</th>
            <th width="10%">发起时间</th>
            <th width="10%">入库(作废)时间</th>
            <th width="10%">入库状态</th>
            <th width="10%">操作</th>
        </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
    <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>
<!-- script start -->
<jsp:include page="/WEB-INF/view/commons/js.jsp" />
<script type="text/javascript">
    $(document).ready(function(e) {
        var table = $("#table_data").dataTable({
            ajax: function(data, callback, settings){
                tableAjax($("#searchForm"),data, callback, settings);
            },
            //列表表头字段
            columns: [
                { "data": "inCode",name:"in_code",orderable:false  },
                { "data": "inTitle",name:"in_title",orderable:false  },
                { "data": "orgName",name:"org_name",orderable:false },
                { "data": "agentName",name:"agent_name",orderable:false },
                { "data": "actionTimeStr",name:"action_time" },
                { "data": "inTimeStr",name:"in_time",orderable:false  },
                { "data": "inStatusStr",name:"in_status",orderable:false },
                {
                    "data": "action",orderable:false,
                    "render": function ( data, type, row, meta ) {
                        var _in = "<shiro:hasPermission name='APP_MATERIALS_IN:action'><a href='javacript:void(0);' onclick=\"instorage('"+row.id+"')\" >入库</a>&nbsp;&nbsp;</shiro:hasPermission>";
                        var info = "<a href='javacript:void(0);' onclick=\"show_in('"+row.id+"')\" >查看</a>&nbsp;&nbsp;";
                        var _invalid = "<shiro:hasPermission name='APP_MATERIALS_IN:invalid'><a href='javacript:void(0);' onclick=\"show_invalid('"+row.id+"')\">作废</a>&nbsp;&nbsp;</shiro:hasPermission>";
                        var edit = "<shiro:hasPermission name='APP_MATERIALS_IN:edit'><a href='javacript:void(0);' onclick=\"handlerShow('"+row.id+"')\">编辑</a>&nbsp;&nbsp;</shiro:hasPermission>"
                        var del = "<shiro:hasPermission name='APP_MATERIALS_IN:delete'><a href='javacript:void(0);' onclick=\"handlerDelete('"+ row.id +"')\">删除</a>&nbsp;&nbsp;</shiro:hasPermission>"
                        if(row.inStatus == 2 ){ return _invalid+info; }
                        if(row.inStatus == 3 ){ return info; }
                        if(row.inStatus == 1 ){ return _in+edit+del+info; }
                        return "";
                    }
                }
            ]
    }).api();
        //查询条件
        $("#searchForm").submit(function(){
            table.ajax.reload();
            return false;
        });

        $("#selorgtype").change(function (){
            var orgtype = $(this).val();
            if(orgtype == '1'){
                $("#inOrg").css("display","block");
                $("#outOrg").css("display","none");
                $("#orgId").val($("#selinorg").val());
            }else{
                $("#inOrg").css("display","none");
                $("#outOrg").css("display","block");
                $("#orgId").val($("#seloutorg").val());
            }
        });

        $("#selinorg").change(function(){
            var orgid = $(this).val();
            $("#orgId").val(orgid);
        });

        $("#seloutorg").change(function(){
            var orgid = $(this).val();
            $("#orgId").val(orgid);
        });
    });

    //跳转进入入库单签署页面
    function instorage (id){
        var option={
            url:"appMaterialsIn/inSign/"+id,
            title:"入库单签署",
            width:'60%',
            height:'90%'
        };
        openIframe(option);
    }

    //编辑入库单
    function handlerShow(id){
        var option={
            url:"appMaterialsIn/edit/"+id,
            title:"编辑入库单",
            width:$(window).width() + "px",
            height:$(window).height() + "px"
        };
        openIframe(option);
    }

    //查看入库单签署过后的文件
    function show_in(id){
        var option={
            url:"appMaterialsIn/inSignPrint/"+id,
            title:"查看入库单",
            width:'60%',
            height:'90%'
        };
        openIframe(option);
    }

    // 删除
    function handlerDelete(id){
        layer.confirm("确定要删除此记录吗?", function(index) {
            layer.close(index);
            $.ajax({
                url: "appMaterialsIn/delete/" + id,
                type: "DELETE",
                dataType: "json",
                success: function (data) {
                    if(data.success){
                        $('#searchForm').submit();
                    }else{
                        layer.alert(data.msg);
                    }
                }
            });
        });
    }
    //作废当前单据
    function show_invalid(id){
        layer.prompt({
            formType: 2,
            value: '',
            title: '请输入作废原因',
        }, function(value, index, elem) {
            if($.trim(value)!=''){
                $.ajax({
                    type: "POST",
                    url: "appMaterialsIn/invalid",
                    data: {"invalidRemark":$.trim(value),"id":id},
                    dataType:'json',
                    success:function(data){
                        if(data.success){
                            layer.msg('作废成功.',{icon: 1});
                            $('#searchForm').submit();
                        }else{
                            layer.msg('作废失败.',{icon: 2});
                        }
                    }
                });
            }
            layer.close(index);
        });
    }
</script>
<!-- script end -->
</body>
</html>